<template>
  <d2-container>
    <div>
      <el-form :inline="true" class="demo-form-inline">
        <el-form-item>
          <el-select size="small" v-model="statusVal" placeholder="请选择审核状态">
            <el-option v-for="item in statuslist" :key="item.value" :label="item.label" :value="item.value"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-input clearable placeholder="请输入订单号" size="small" v-model="searchList.searchValue"></el-input>
        </el-form-item>
        <el-form-item>
          <el-input clearable placeholder="请输入店铺名字" size="small" v-model="searchList.shop_name"></el-input>
        </el-form-item>
        <el-form-item>
          <el-date-picker size="small" v-model="searchList.timelist" type="daterange" align="right"
                          value-format="yyyy-MM-dd" unlink-panels range-separator="至"
                          start-placeholder="开始日期" end-placeholder="结束日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" size="mini" @click="init">搜索</el-button>
        </el-form-item>
      </el-form>
      <el-table v-loading="loading" border :data="tableData" style="width: 100%" header-align="center">
        <el-table-column type="index" label="序号" width="" align="center"></el-table-column>
        <el-table-column prop="task_order" label="订单编号" align="center"></el-table-column>
        <el-table-column prop="shop_name" label="店铺名" align="center"></el-table-column>
        <el-table-column prop="tb_name" label="刷手会员号" width="" align="center"></el-table-column>
        <el-table-column prop="baby_id" label="宝贝ID" width="" align="center"></el-table-column>
        <el-table-column prop="title" label="评价内容" width="" align="center"></el-table-column>
        <el-table-column prop="screenshot" label="评价内容图片" width="" align="center">
          <template slot-scope="scope">
            <viewer :images="scope.row.img">
              <img v-if="scope.row.img.length!=0" v-for="i in scope.row.img" :src="i" style="width:50px;height:50px;" alt="">
            </viewer>
            <span v-if="scope.row.img.length==0">暂无上传截图</span>
          </template>
        </el-table-column>
        <el-table-column label="买手上传截图" width="" align="center">
          <template slot-scope="scope">
            <viewer :images="scope.row.evaluate_img">
              <img v-if="scope.row.evaluate_img!=''" :src="scope.row.evaluate_img" style="width:50px;height:50px;" alt="">
            </viewer>
            <span v-if="scope.row.evaluate_img==''">暂无上传截图</span>
          </template>
        </el-table-column>
        <el-table-column prop="create_time" label="创建时间" align="center"></el-table-column>
        <el-table-column fixed="right" label="审核" width="" align="center">screenshot
          <template slot-scope="scope">
            <el-button v-if="scope.row.status == 1" type="danger">等待买手上传评价</el-button>
            <div v-if="scope.row.status == 2">
              <el-button @click="onPass(scope.row,1)" type="primary" plain size="mini">通过</el-button>
              <el-button @click="onPass(scope.row,2)" size="mini" type="danger" plain>拒绝</el-button>
            </div>
            <el-button v-if="scope.row.status == 3" type="success" size="mini" plain disabled>已通过</el-button>
            <el-button v-if="scope.row.status == 4" type="info" size="mini" plain disabled>已拒绝</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination :page-size="20" :current-page="searchList.pn" layout="total,prev, pager, next"
                     :total="searchList.total" @current-change="pnChange">
      </el-pagination>
    </div>
  </d2-container>
</template>

<script>
import {evaluate_approved_list, userinfo, evaluate_approved_adopt, evaluate_approved_refuse} from '../../../api/api'
import moment from "moment";

export default {
  name: "AdminRefundList",
  data() {
    return {
      tableData: [],
      searchList: {
        searchValue: "",
        timelist: [new Date('2020-1-1 0:00:00'), new Date('2090-1-1 0:00:00')],
        pn: 1,
        total: 0,
        shop_name: "",
      },
      loading: false,
      statusVal: 0,
      statuslist: [
        {
          value: 0,
          label: '全部'
        },
        {
          value: 3,
          label: '审核通过'
        }, {
          value: 2,
          label: '提交待审核'
        }, {
          value: 1,
          label: '等待买手评价'
        }, {
          value: 4,
          label: '审核拒绝'
        }],
    }
  },
  mounted() {
    let params = {
      page: this.searchList.pn,
      page_size: 20,
      begin_time: moment(this.searchList.timelist[0]).format('YYYY-MM-DD 00:00:00'),
      end_time: moment(this.searchList.timelist[1]).format('YYYY-MM-DD 23:59:59'),
    }
    this.getorderList(params)
  },
  methods: {
    //获取用户信息
    getUser() {
      userinfo().then(res => {
        console.log('个人信息', res)
        if (res.Status == 200) {
          this.$emit('getMoney', res.Data.money)
        } else {
          this.$message.error(res.Message)
        }
      })
    },
    pnChange(pn) {
      this.searchList.pn = pn
      let params = {
        task_order: this.searchList.searchValue,
        begin_time: this.searchList.timelist[0],
        end_time: this.searchList.timelist[1],
        page: pn,
        shop_name: this.searchList.shop_name,
        page_size: 20,
        status: this.statusVal
      }
      this.getorderList(params)
    },
    //获取订单列表
    getorderList(params) {
      evaluate_approved_list(params).then(res => {
        console.log(res);
        if (res.Status == 200) {
          this.tableData = res.Data.map((item) => {
            item.img = JSON.parse(item.img)
            return item
          })
          this.searchList.total = res.Count
        } else {
          this.$message.error(res.Message)
        }
      })
    },
    //查询
    init() {
      console.log(this.searchList.timelist);
      // if (this.searchList.timelist.length > 0) {
      //   this.searchList.timelist[0] = this.searchList.timelist[0] + '00:00:00'
      //   this.searchList.timelist[1] = this.searchList.timelist[1] + '23:59:59'
      // }
      let params = {
        task_order: this.searchList.searchValue,
        begin_time: moment(this.searchList.timelist[0]).format('YYYY-MM-DD HH:mm:ss'),
        end_time: moment(this.searchList.timelist[1]).format('YYYY-MM-DD HH:mm:ss'),
        shop_name: this.searchList.shop_name,
        page_size: 20,
        page: 1,
        status: this.statusVal
      }
      this.getorderList(params)
    },
    //通过
    onPass(row, idx) {
      console.log('row', row)
      let params = {
        id: row.id,
      }
      if (idx === 1) {
        evaluate_approved_adopt(params).then(res => {
          console.log('成功', res)
          if (res.Status == 200) {
            this.$message({
              type: 'success',
              message: res.Message
            });
            let paraming = {
              task_order: this.searchList.searchValue,
              begin_time: this.searchList.timelist[0],
              end_time: this.searchList.timelist[1],
              page: this.searchList.pn,
              shop_name: this.searchList.shop_name,
              page_size: 20,
              status: this.statusVal
            }
            this.getorderList(paraming)
          } else {
            this.$message({
              type: 'error',
              message: res.Message
            });
          }
        })
      } else {
        let params = {
          id: row.id,
        }
        this.open(params)
      }
    },
    open(params) {
      this.$prompt('请输入拒绝原因', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
      }).then(({value}) => {
        params.note = value
        evaluate_approved_refuse(params).then(res => {
          console.log('拒绝', res)
          if (res.Status == 200) {
            this.$message({
              type: 'success',
              message: res.Message
            });
            let paraming = {
              task_order: this.searchList.searchValue,
              begin_time: this.searchList.timelist[0],
              end_time: this.searchList.timelist[1],
              page: this.searchList.pn,
              shop_name: this.searchList.shop_name,
              page_size: 20,
              status: this.statusVal
            }
            this.getorderList(paraming)
          } else {
            this.$message({
              type: 'error',
              message: res.Message
            });
          }
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '取消输入'
        });
      });
    }
  }
}
</script>

<style scoped>

</style>
